package cn.lili.xiaoran.controller;

import cn.lili.xiaoran.entity.LiQuestionsFabulous;
import cn.lili.xiaoran.entity.dtos.LiQuestionsFabulousDTO;
import cn.lili.xiaoran.service.LiQuestionsFabulousService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import cn.lili.mybatis.util.PageUtil;
import cn.lili.common.enums.ResultUtil;
import cn.lili.common.vo.PageVO;
import cn.lili.common.vo.SearchVO;
import cn.lili.common.vo.ResultMessage;
import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.RequiredArgsConstructor;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

import javax.annotation.Resource;

/**
 * 喜欢表(LiQuestionsFabulous)表控制层
 *
 * @author makejava
 * @since 2022-08-14 22:05:10
 */
@RestController
@Api(tags = "liQuestionsFabulous接口")
@RequestMapping("/buyer/lili/liQuestionsFabulous")
@Transactional(rollbackFor = Exception.class)
public class LiQuestionsFabulousController {
    /**
     * 服务对象
     */
    @Resource
    private LiQuestionsFabulousService liQuestionsFabulousService;

    @GetMapping(value = "/{id}")
    @ApiOperation(value = "查看${tableInfo.description}详情")
    public ResultMessage<LiQuestionsFabulous> get(@PathVariable Integer id) {

        LiQuestionsFabulous liQuestionsFabulous = liQuestionsFabulousService.getById(id);
        return new ResultUtil<LiQuestionsFabulous>().setData(liQuestionsFabulous);
    }

    @GetMapping
    @ApiOperation(value = "分页获取${tableInfo.description}")
    public ResultMessage<IPage<LiQuestionsFabulous>> getByPage(LiQuestionsFabulousDTO page) {
        IPage<LiQuestionsFabulous> data = this.liQuestionsFabulousService.page(PageUtil.initPage(page), page.queryWrapper());
        return new ResultUtil<IPage<LiQuestionsFabulous>>().setData(data);
    }

    @PostMapping
    @ApiOperation(value = "新增${tableInfo.description}")
    public ResultMessage<LiQuestionsFabulous> save( LiQuestionsFabulous liQuestionsFabulous) {

        if (this.liQuestionsFabulousService.save(liQuestionsFabulous)) {
            return new ResultUtil<LiQuestionsFabulous>().setData(liQuestionsFabulous);
        }
        return new ResultUtil<LiQuestionsFabulous>().setErrorMsg("未知异常，请稍后重试");
    }

    @PutMapping("/{id}")
    @ApiOperation(value = "更新${entity.description}")
    public ResultMessage<LiQuestionsFabulous> update(@PathVariable String id, LiQuestionsFabulous liQuestionsFabulous) {
        if (this.liQuestionsFabulousService.updateById(liQuestionsFabulous)) {
            return new ResultUtil<LiQuestionsFabulous>().setData(liQuestionsFabulous);
        }
        return new ResultUtil<LiQuestionsFabulous>().setErrorMsg("未知异常，请稍后重试");
    }

    @DeleteMapping(value = "/{ids}")
    @ApiOperation(value = "删除喜欢表")
    public ResultMessage<Object> delAllByIds(@PathVariable List ids) {

        liQuestionsFabulousService.removeByIds(ids);
        return ResultUtil.success("成功删除");
    }


}

